import serial

class Oled():
    def __init__(self, port="/dev/ttyACM0") -> None:
        try:
            self.ser = serial.Serial(port, baudrate=115200, timeout=1)
            self.ser.flushInput()
        except Exception as e:
            print(e)
            assert(1)
        
    def page_mode(self):
        self.ser.write(("PAGE"+'\r\n').encode())
    def line_mode(self):
        self.ser.write(("LINE"+'\r\n').encode())
    
    def print(self, text):
        text = str(text).replace('\n','&n') +'\r\n'
        print(text)
        self.ser.write(text.encode())


if __name__ == '__main__':
    oled = Oled()
    oled.line_mode()
    oled.print("test\ntest")